
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta charset="utf-8" />
  
  <!-- Licensed under the Apache 2.0 License -->
  <link rel="stylesheet" type="text/css" href="../_static/fonts/open-sans/stylesheet.css" />
  <!-- Licensed under the SIL Open Font License -->
  <link rel="stylesheet" type="text/css" href="../_static/fonts/source-serif-pro/source-serif-pro.css" />
  <link rel="stylesheet" type="text/css" href="../_static/css/bootstrap.min.css" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
    <title>Evaluate solutions &#8212; jMetalPy 1.5.3 documentation</title>
    <link rel="stylesheet" href="../_static/guzzle.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <link rel="stylesheet" type="text/css" href="../_static/custom.css" />
    <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/language_data.js"></script>
    <script crossorigin="anonymous" integrity="sha256-Ae2Vz/4ePdIu6ZyI/5ZGsYnb+m0JlOmKPjt6XZ9JJkA=" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js"></script>
    <script async="async" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <script type="text/x-mathjax-config">MathJax.Hub.Config({"tex2jax": {"inlineMath": [["$", "$"], ["\\(", "\\)"]], "processEscapes": true, "ignoreClass": "document", "processClass": "math|output_area"}})</script>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="Front visualization" href="visualization.html" />
    <link rel="prev" title="Extending algorithms" href="observer.html" />
  
   

  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="visualization.html" title="Front visualization"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="observer.html" title="Extending algorithms"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../index.html">jMetalPy 1.5.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../tutorials.html" accesskey="U">Getting started</a> &#187;</li> 
      </ul>
    </div>
    <div class="container-wrapper">

      <div id="mobile-toggle">
        <a href="#"><span class="glyphicon glyphicon-align-justify" aria-hidden="true"></span></a>
      </div>
  <div id="left-column">
    <div class="sphinxsidebar"><a href="
    ../index.html" class="text-logo">
    <img src="_static/jmetalpy.png" class="img-fluid" alt="jMetalPy 1.5.3 documentation">
    <br>
</a>

<div class="sidebar-block">
  <div class="sidebar-wrapper">
    Python version of the jMetal framework
  </div>
</div>
<div class="sidebar-block">
  <div class="sidebar-wrapper">
    <h2>Table Of Contents</h2>
  </div>
  <div class="sidebar-toc">
    
    
      <ul class="current">
<li class="toctree-l1 current"><a class="reference internal" href="../tutorials.html">Getting started</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="problem.html">Defining new problems</a></li>
<li class="toctree-l2"><a class="reference internal" href="observer.html">Extending algorithms</a></li>
<li class="toctree-l2 current"><a class="current reference internal" href="#">Evaluate solutions</a></li>
<li class="toctree-l2"><a class="reference internal" href="visualization.html">Front visualization</a></li>
<li class="toctree-l2"><a class="reference internal" href="experiment.html">Experiments</a></li>
<li class="toctree-l2"><a class="reference internal" href="statistics.html">Statistical analysis</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../multiobjective.algorithms.html">Multi-objective algorithms</a></li>
<li class="toctree-l1"><a class="reference internal" href="../singleobjective.algorithms.html">Single-objective algorithms</a></li>
<li class="toctree-l1"><a class="reference internal" href="../operators.html">Operators</a></li>
<li class="toctree-l1"><a class="reference internal" href="../problems.html">Problems</a></li>
</ul>

    
  </div>
</div>
<div class="sidebar-block">
  <div class="sidebar-wrapper">
    <h2>Contents</h2>
    <div class="sidebar-localtoc">
      <ul>
<li><a class="reference internal" href="#">Evaluate solutions</a><ul>
<li><a class="reference internal" href="#sequential">Sequential</a><ul>
<li><a class="reference internal" href="#api">API</a></li>
</ul>
</li>
<li><a class="reference internal" href="#parallel-and-distributed">Parallel and distributed</a><ul>
<li><a class="reference internal" href="#id1">API</a></li>
</ul>
</li>
</ul>
</li>
</ul>

    </div>
  </div>
</div>
<div class="sidebar-block">
  <div class="sidebar-wrapper">
    <div id="main-search">
      <form class="form-inline" action="../search.html" method="GET" role="form">
        <div class="input-group">
          <input name="q" type="text" class="form-control" placeholder="Search...">
        </div>
        <input type="hidden" name="check_keywords" value="yes" />
        <input type="hidden" name="area" value="default" />
      </form>
    </div>
  </div>
</div>
      
    </div>
  </div>
        <div id="right-column">
          
          <nav aria-label="breadcrumb">
            <ol class="breadcrumb">
              <li class="breadcrumb-item"><a href="../index.html">Docs</a></li>
              
              <li class="breadcrumb-item"><a href="../tutorials.html">Getting started</a></li>
              
              <li class="breadcrumb-item">Evaluate solutions</li>
            </ol>
          </nav>
          
          <div class="document clearer body">
            
  <div class="section" id="evaluate-solutions">
<h1>Evaluate solutions<a class="headerlink" href="#evaluate-solutions" title="Permalink to this headline">¶</a></h1>
<p>The lifecycle of metaheuristics often requires to evaluate list of solutions on every iteration. In evolutionary algorithms, for example, this list of solutions is known as <em>population</em>.</p>
<p>In order to evaluate a population, NSGA-II (and in general, any generational algorithms in jMetalPy) uses an evaluator object.</p>
<div class="section" id="sequential">
<h2>Sequential<a class="headerlink" href="#sequential" title="Permalink to this headline">¶</a></h2>
<p>The default evaluator runs in a sequential fashion (i.e., one solution at a time):</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">jmetal.util.evaluator</span> <span class="kn">import</span> <span class="n">SequentialEvaluator</span>

<span class="n">algorithm</span> <span class="o">=</span> <span class="n">NSGAII</span><span class="p">(</span>
   <span class="n">problem</span><span class="o">=</span><span class="n">problem</span><span class="p">,</span>
   <span class="n">population_size</span><span class="o">=</span><span class="mi">100</span><span class="p">,</span>
   <span class="n">offspring_population_size</span><span class="o">=</span><span class="mi">100</span><span class="p">,</span>
   <span class="o">...</span>
   <span class="n">population_evaluator</span> <span class="o">=</span> <span class="n">SequentialEvaluator</span><span class="p">(),</span>
 <span class="p">)</span>
</pre></div>
</div>
<div class="section" id="api">
<h3>API<a class="headerlink" href="#api" title="Permalink to this headline">¶</a></h3>
<dl class="class">
<dt id="jmetal.util.evaluator.SequentialEvaluator">
<em class="property">class </em><code class="sig-prename descclassname">jmetal.util.evaluator.</code><code class="sig-name descname">SequentialEvaluator</code><a class="reference internal" href="../_modules/jmetal/util/evaluator.html#SequentialEvaluator"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#jmetal.util.evaluator.SequentialEvaluator" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">jmetal.util.evaluator.Evaluator</span></code></p>
<dl class="method">
<dt id="jmetal.util.evaluator.SequentialEvaluator.evaluate">
<code class="sig-name descname">evaluate</code><span class="sig-paren">(</span><em class="sig-param">solution_list: List[S], problem: jmetal.core.problem.Problem</em><span class="sig-paren">)</span> &#x2192; List[S]<a class="reference internal" href="../_modules/jmetal/util/evaluator.html#SequentialEvaluator.evaluate"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#jmetal.util.evaluator.SequentialEvaluator.evaluate" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

</dd></dl>

</div>
</div>
<div class="section" id="parallel-and-distributed">
<h2>Parallel and distributed<a class="headerlink" href="#parallel-and-distributed" title="Permalink to this headline">¶</a></h2>
<p>Solutions can also be evaluated in parallel, using threads or processes:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">jmetal.util.evaluator</span> <span class="kn">import</span> <span class="n">MapEvaluator</span>
<span class="kn">from</span> <span class="nn">jmetal.util.evaluator</span> <span class="kn">import</span> <span class="n">MultiprocessEvaluator</span>
</pre></div>
</div>
<p>jMetalPy includes an evaluator based on Apache Spark, so the solutions can be evaluated in a variety of parallel systems (multicores, clusters):</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">jmetal.util.evaluator</span> <span class="kn">import</span> <span class="n">SparkEvaluator</span>

<span class="n">algorithm</span> <span class="o">=</span> <span class="n">NSGAII</span><span class="p">(</span>
   <span class="n">problem</span><span class="o">=</span><span class="n">problem</span><span class="p">,</span>
   <span class="n">population_size</span><span class="o">=</span><span class="mi">100</span><span class="p">,</span>
   <span class="n">offspring_population_size</span><span class="o">=</span><span class="mi">100</span><span class="p">,</span>
   <span class="o">...</span>
   <span class="n">population_evaluator</span> <span class="o">=</span> <span class="n">SparkEvaluator</span><span class="p">(</span><span class="n">processes</span><span class="o">=</span><span class="mi">8</span><span class="p">),</span>
 <span class="p">)</span>
</pre></div>
</div>
<p>Or by means of Dask:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">jmetal.util.evaluator</span> <span class="kn">import</span> <span class="n">DaskEvaluator</span>

<span class="n">algorithm</span> <span class="o">=</span> <span class="n">NSGAII</span><span class="p">(</span>
   <span class="n">problem</span><span class="o">=</span><span class="n">problem</span><span class="p">,</span>
   <span class="n">population_size</span><span class="o">=</span><span class="mi">100</span><span class="p">,</span>
   <span class="n">offspring_population_size</span><span class="o">=</span><span class="mi">100</span><span class="p">,</span>
   <span class="o">...</span>
   <span class="n">population_evaluator</span> <span class="o">=</span> <span class="n">DaskEvaluator</span><span class="p">(),</span>
 <span class="p">)</span>
</pre></div>
</div>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p><code class="code docutils literal notranslate"><span class="pre">SparkEvaluator</span></code> and <code class="code docutils literal notranslate"><span class="pre">DaskEvaluator</span></code> requires pySpark and Dask, respectively.</p>
</div>
<div class="section" id="id1">
<h3>API<a class="headerlink" href="#id1" title="Permalink to this headline">¶</a></h3>
<dl class="class">
<dt id="jmetal.util.evaluator.MapEvaluator">
<em class="property">class </em><code class="sig-prename descclassname">jmetal.util.evaluator.</code><code class="sig-name descname">MapEvaluator</code><span class="sig-paren">(</span><em class="sig-param">processes: int = None</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/jmetal/util/evaluator.html#MapEvaluator"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#jmetal.util.evaluator.MapEvaluator" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">jmetal.util.evaluator.Evaluator</span></code></p>
<dl class="method">
<dt id="jmetal.util.evaluator.MapEvaluator.evaluate">
<code class="sig-name descname">evaluate</code><span class="sig-paren">(</span><em class="sig-param">solution_list: List[S], problem: jmetal.core.problem.Problem</em><span class="sig-paren">)</span> &#x2192; List[S]<a class="reference internal" href="../_modules/jmetal/util/evaluator.html#MapEvaluator.evaluate"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#jmetal.util.evaluator.MapEvaluator.evaluate" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

</dd></dl>

<dl class="class">
<dt id="jmetal.util.evaluator.MultiprocessEvaluator">
<em class="property">class </em><code class="sig-prename descclassname">jmetal.util.evaluator.</code><code class="sig-name descname">MultiprocessEvaluator</code><span class="sig-paren">(</span><em class="sig-param">processes: int = None</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/jmetal/util/evaluator.html#MultiprocessEvaluator"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#jmetal.util.evaluator.MultiprocessEvaluator" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">jmetal.util.evaluator.Evaluator</span></code></p>
<dl class="method">
<dt id="jmetal.util.evaluator.MultiprocessEvaluator.evaluate">
<code class="sig-name descname">evaluate</code><span class="sig-paren">(</span><em class="sig-param">solution_list: List[S], problem: jmetal.core.problem.Problem</em><span class="sig-paren">)</span> &#x2192; List[S]<a class="reference internal" href="../_modules/jmetal/util/evaluator.html#MultiprocessEvaluator.evaluate"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#jmetal.util.evaluator.MultiprocessEvaluator.evaluate" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

</dd></dl>

<dl class="class">
<dt id="jmetal.util.evaluator.SparkEvaluator">
<em class="property">class </em><code class="sig-prename descclassname">jmetal.util.evaluator.</code><code class="sig-name descname">SparkEvaluator</code><span class="sig-paren">(</span><em class="sig-param">processes: int = 8</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/jmetal/util/evaluator.html#SparkEvaluator"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#jmetal.util.evaluator.SparkEvaluator" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">jmetal.util.evaluator.Evaluator</span></code></p>
<dl class="method">
<dt id="jmetal.util.evaluator.SparkEvaluator.evaluate">
<code class="sig-name descname">evaluate</code><span class="sig-paren">(</span><em class="sig-param">solution_list: List[S], problem: jmetal.core.problem.Problem</em><span class="sig-paren">)</span> &#x2192; List[S]<a class="reference internal" href="../_modules/jmetal/util/evaluator.html#SparkEvaluator.evaluate"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#jmetal.util.evaluator.SparkEvaluator.evaluate" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

</dd></dl>

<dl class="class">
<dt id="jmetal.util.evaluator.DaskEvaluator">
<em class="property">class </em><code class="sig-prename descclassname">jmetal.util.evaluator.</code><code class="sig-name descname">DaskEvaluator</code><span class="sig-paren">(</span><em class="sig-param">scheduler='processes'</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/jmetal/util/evaluator.html#DaskEvaluator"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#jmetal.util.evaluator.DaskEvaluator" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">jmetal.util.evaluator.Evaluator</span></code></p>
<dl class="method">
<dt id="jmetal.util.evaluator.DaskEvaluator.evaluate">
<code class="sig-name descname">evaluate</code><span class="sig-paren">(</span><em class="sig-param">solution_list: List[S], problem: jmetal.core.problem.Problem</em><span class="sig-paren">)</span> &#x2192; List[S]<a class="reference internal" href="../_modules/jmetal/util/evaluator.html#DaskEvaluator.evaluate"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#jmetal.util.evaluator.DaskEvaluator.evaluate" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

</dd></dl>

</div>
</div>
</div>


          </div>
            
  <div class="footer-relations">
    
      <div class="float-left">
        <a class="btn btn-outline btn-sm" href="observer.html" title="previous chapter (use the left arrow)">← Extending algorithms</a>
      </div>
    
      <div class="float-right">
        <a class="btn btn-outline btn-sm" href="visualization.html" title="next chapter (use the right arrow)">Front visualization →</a>
      </div>
    </div>
    <div class="clearer"></div>
  
        </div>
        <div class="clearfix"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="visualization.html" title="Front visualization"
             >next</a> |</li>
        <li class="right" >
          <a href="observer.html" title="Extending algorithms"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../index.html">jMetalPy 1.5.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../tutorials.html" >Getting started</a> &#187;</li> 
      </ul>
    </div>
<script type="text/javascript">
  $("#mobile-toggle a").click(function () {
    $("#left-column").toggle();
  });
</script>
<script type="text/javascript" src="../_static/js/bootstrap.js"></script>
  <div class="footer">
    &copy; Copyright 2019, Antonio Benítez-Hidalgo. Created using <a href="http://sphinx.pocoo.org/">Sphinx</a>.
  </div>
  </body>
</html>